{include file="common/header"/}
<style> .layui-iconpicker-body.layui-iconpicker-body-page .hide {display: none;}</style>
<div class="lemo-container">
    <div class="lemo-main">
        <div class="admin-main layui-anim layui-anim-upbit">
            <fieldset class="layui-elem-field layui-field-title">
                <legend>{:lang('add')}院系节点</legend>
            </fieldset>
            <form class="layui-form layui-form-pane" lay-filter="form">
                <input type="hidden" name="id">
                <div class="layui-form-item">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="title" readonly lay-verify="required" placeholder="{:lang('pleaseEnter')}名称"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">选择题目</label>
                    <div class="layui-input-inline">
                        <select name="topic_id" lay-verify="required" lay-filter="pid">
                            {volist name="topicList" id="vo"}
                            <option value="{$vo.id}">{$vo.title}</option>
                            {/volist}
                        </select>
                    </div>
                </div>

<!--                <div class="layui-form-item layui-form-text" style="width: 610px">-->
<!--                    <label class="layui-form-label">题目描述</label>-->
<!--                    <div class="layui-input-block">-->
<!--                                    <textarea name="desc" class="layui-textarea"-->
<!--                                              placeholder="描述"></textarea>-->
<!--                    </div>-->
<!--                </div>-->

                <div class="layui-form-item">
                    <div class="layui-input-inline">
                        <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">立即提交</button>
                        <a data-href="{:url('allocation')}" class="layui-btn layui-btn-primary back">返回</a>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

{include file="common/footer"/}
<script>
    layui.config({
        base: '/static/plugins/layui/extend/'
    }).extend({
        iconPickerFa: 'iconPicker/iconPickerFa'
    }).use(['form', 'layer','iconPickerFa'], function () {
        var form = layui.form,layer = layui.layer,$= layui.jquery;
        var iconPickerFa = layui.iconPickerFa;
        var info  = {:json_encode($info)};
        console.log(info)
        var url = "{:url('add')}";
        var icon = '';
        if(info){
            form.val('form',info);
            url = "{:url('edit')}";
        }
        //返回页面
        $('body').on('click','.back',function() {
            var url = $(this).attr('data-href');
            layer.closeAll();
            window.parent.location.href=url;

        });
        form.on('submit(submit)', function (data) {
            if (data.field.topic_id == ''){
                return layer.msg('请选择题目',{time:1000,icon:2});
            }
            $.post(url,data.field,function(res){
                if(res.code > 0){
                    layer.msg(res.msg,{time:1000,icon:1},function(){
                        location.href = "{:url('allocation')}"
                    });
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                }
            });
        })
    });
</script>